/*
 * �������� 2005-10-19
 *
 * TODO Ҫ��Ĵ���ɵ��ļ���ģ�壬��ת��
 * ���� �� ��ѡ�� �� Java �� ������ʽ �� ����ģ��
 */
package com.util;

import java.sql.*;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;

import java.io.InputStream;
import java.util.Properties;


public class ConnDatabase {
	private String driver="";		
	private String dburl="";
	private String dbuser="";
	private String dbpassword="";
	Document document = null;
	//public Connection con = null;
	//public Statement stmt = null;
	//public ResultSet rs = null, rsp = null;
	public String sql = "", sResult = "";
	// �����ļ����
    private static String configFile="conf.properties";
    private static Properties properties = null;
	
    //
	public ConnDatabase() 
	{	
	}
	
	/**
	 * ��������:��ȡ��ݿ��l��
	 * 
	 * @param ��
	 * 
	 * @return Connection����
	 */



	
		/** ȡ���������� */
		public String getProperty(String key) {
		return properties.getProperty(key);
		}
		
		/** ȡ���������ԣ��޴����ԣ�����Ĭ��ֵ�� */
		public String getProperty(String key, String defaultValue) {
		return properties.getProperty(key, defaultValue);
		}

	public String getNodeValue(List list, String Node)
	{
		    Iterator it = list.iterator();
		    if (it.hasNext()) {
		      Element styleElement = (Element) it.next();
		      // List memo = styleElement.elements("smemo");
		      Iterator memo = styleElement.elementIterator(Node);
		      if (memo.hasNext()) {
		        Element memostring = (Element) memo.next();
		        return memostring.getTextTrim();
		      }
		      else {
		        return "";
		      }
		    }
		    else {
		      return "";
		    }
  }
	/**
	 * ��������:��ȡ��ݿ��¼��
	 * 
	 * @param sql��ѯ���
	 * 
	 * @return ResultSet��ݼ�����
	 
	public java.sql.ResultSet dbExecuteQuery(String sql) throws Exception {
		this.dbConnection();
		if (con != null && stmt != null) {
			try {		
				this.rs = this.stmt.executeQuery(sql);
				return rs;

			} catch (SQLException sqle) {
				System.out.println(sqle);

			}
		} else {
			System.out.println("database connect error");
		}
		return null;
	} */

	/**
	 * ��������:������ݿ��¼��
	 * 
	 * @param sql��ѯ���
	 * 
	 * @return ��
	
	public int dbExecuteUpdate(String sql) {
		int cou=0;
		try {
			if(con.equals(null)){this.dbConnection();}
			cou=stmt.executeUpdate(sql);
		} catch (SQLException ex) {
			System.err.println("ExeUpdate:" + ex.getMessage());
		}
		catch(Exception ex){}
		finally{
			
		}
		return cou;
	} */

	/**
	 * ��������:�ر���ݿ�l��
	 * 
	 * @param ��
	 * 
	 * @return ��
	 */
	public void CloseConnection(Connection conn,Statement st,ResultSet rs) 
	{
		if (rs != null)
		{
			try{
				rs.close();
				rs=null;
			}catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		if (st != null)
		{
			try
			{
				st.close();
				st=null;
			}catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		if (conn != null)
		{
			try
			{
				conn.close();
				conn=null;
			}catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
	}
	
}